package com.api.shopapi.mapper;

import com.api.shopapi.entity.Report;
import com.api.shopapi.entity.dto.ReportDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ReportMapper {

    @Insert("insert into report (ReportCode,UserCode,HospitalName,InspectTime,CreateTime) values " +
            "(#{report.ReportCode},#{report.UserCode},#{report.HospitalName},#{report.InspectTime},#{report.CreateTime})")
    int insert(@Param("report") Report report);

    @Update("update report set UserCode=#{report.UserCode},HospitalName=#{report.HospitalName},InspectTime=#{report.InspectTime}," +
            "where ReportCode=#{report.ReportCode}")
    int update(@Param("report") Report report);

    @Delete("delete from report where ReportCode=#{reportCode}")
    int delete(@Param("reportCode") String reportCode);

    @Select("select * from report where ReportCode=#{reportCode} limit 1")
    Report getByReportCode(@Param("reportCode") String reportCode);

    @Select("<script>" +
            "select * from report where UserCode=#{userCode} "+
            "order by InspectTime desc" +
            "</script>")
    List<Report> getPageList(@Param("userCode") String userCode);


    @Select("<script>" +
            "select r.*,u.Name as userName from report r left join user u on r.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='userName !=null and userName!=\"\" '>" +
            " and u.Name like concat('%',#{userName},'%') " +
            "</if>" +
            "order by CreateTime desc" +
            "</script>")
    List<ReportDTO> GetPageByGovernment(@Param("userName") String userName,@Param("governmentCode") String governmentCode);
}
